package com.recycle.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.recycle.common.annotation.Log;
import com.recycle.common.core.controller.BaseController;
import com.recycle.common.core.domain.CommonResult;
import com.recycle.common.enums.BusinessType;
import com.recycle.system.domain.OrderItem;
import com.recycle.system.service.IOrderItemService;
import com.recycle.common.utils.poi.ExcelUtil;
import com.recycle.common.core.page.TableDataInfo;

/**
 * 订单资源Controller
 *
 * @author recycle
 * @date 2023-04-19
 */
@RestController
@RequestMapping("/system/item")
public class OrderItemController extends BaseController
{
    @Autowired
    private IOrderItemService orderItemService;

    /**
     * 查询订单资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderItem orderItem)
    {
        startPage();
        List<OrderItem> list = orderItemService.selectOrderItemList(orderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "订单资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderItem orderItem)
    {
        List<OrderItem> list = orderItemService.selectOrderItemList(orderItem);
        ExcelUtil<OrderItem> util = new ExcelUtil<OrderItem>(OrderItem.class);
        util.exportExcel(response, list, "订单资源数据");
    }

    /**
     * 获取订单资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{orderItemId}")
    public CommonResult getInfo(@PathVariable("orderItemId") Long orderItemId)
    {
        return success(orderItemService.selectOrderItemByOrderItemId(orderItemId));
    }

    /**
     * 新增订单资源
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "订单资源", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody OrderItem orderItem)
    {
        return toAjax(orderItemService.insertOrderItem(orderItem));
    }

    /**
     * 修改订单资源
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "订单资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody OrderItem orderItem)
    {
        return toAjax(orderItemService.updateOrderItem(orderItem));
    }

    /**
     * 删除订单资源
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "订单资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderItemIds}")
    public CommonResult remove(@PathVariable Long[] orderItemIds)
    {
        return toAjax(orderItemService.deleteOrderItemByOrderItemIds(orderItemIds));
    }
}
